package com.jingxuan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jingxuan.common.result.Result;
import com.jingxuan.dto.response.RankingItemResponse;
import com.jingxuan.service.RankService;

import lombok.extern.slf4j.Slf4j;

/**
 * 排行榜控制器
 */
@Slf4j
@RestController
@RequestMapping("/rank")
public class RankController {
    
    @Autowired
    private RankService rankService;
    
    /**
     * 获取推荐榜
     * GET /rank/recommend?limit=20
     *
     * @param limit 返回数量限制（可选，默认20）
     * @return 推荐榜商品列表
     */
    @GetMapping("/recommend")
    public Result<List<RankingItemResponse>> getRecommendRanking(
            @RequestParam(value = "limit", required = false) Integer limit) {
        log.info("获取推荐榜，limit={}", limit);
        List<RankingItemResponse> ranking = rankService.getRecommendRanking(limit);
        return Result.success(ranking);
    }
    
    /**
     * 获取性价比榜
     * GET /rank/value?limit=20
     *
     * @param limit 返回数量限制（可选，默认20）
     * @return 性价比榜商品列表
     */
    @GetMapping("/value")
    public Result<List<RankingItemResponse>> getValueRanking(
            @RequestParam(value = "limit", required = false) Integer limit) {
        log.info("获取性价比榜，limit={}", limit);
        List<RankingItemResponse> ranking = rankService.getValueRanking(limit);
        return Result.success(ranking);
    }
    
    /**
     * 获取新品榜
     * GET /rank/new-product?limit=20
     *
     * @param limit 返回数量限制（可选，默认20）
     * @return 新品榜商品列表
     */
    @GetMapping("/new-product")
    public Result<List<RankingItemResponse>> getNewProductRanking(
            @RequestParam(value = "limit", required = false) Integer limit) {
        log.info("获取新品榜，limit={}", limit);
        List<RankingItemResponse> ranking = rankService.getNewProductRanking(limit);
        return Result.success(ranking);
    }
}

